<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page import="org.jfree.chart.servlet.*
,java.awt.Color
,java.awt.Font
,org.jfree.chart.ChartFactory
,org.jfree.chart.ChartFrame
,org.jfree.chart.JFreeChart
,org.jfree.chart.axis.CategoryAxis
,org.jfree.chart.axis.CategoryLabelPositions
,org.jfree.chart.axis.NumberAxis
,org.jfree.chart.axis.ValueAxis
,org.jfree.chart.labels.StandardCategoryItemLabelGenerator
,org.jfree.chart.plot.CategoryPlot
,org.jfree.chart.plot.PlotOrientation
,org.jfree.chart.renderer.category.BarRenderer
,org.jfree.chart.title.TextTitle
,org.jfree.data.category.CategoryDataset
,org.jfree.data.category.DefaultCategoryDataset" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'net_bar.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    DefaultCategoryDataset dataset=new DefaultCategoryDataset();
		dataset.addValue(12, "病毒", "1");
		dataset.addValue(13, "病毒", "2");
		dataset.addValue(18, "病毒", "3");
		dataset.addValue(12, "病毒", "4");
		dataset.addValue(21, "病毒", "5");
		dataset.addValue(14, "病毒", "6");
		dataset.addValue(245, "病毒", "8");
		dataset.addValue(45, "病毒", "9");
		dataset.addValue(12, "病毒", "10");
		dataset.addValue(0, "病毒", "11");
		dataset.addValue(0, "病毒", "12");
		dataset.addValue(0, "病毒", "13");
		dataset.addValue(0, "病毒", "14");
		dataset.addValue(0, "病毒", "15");
		dataset.addValue(0, "病毒", "16");
		dataset.addValue(0, "病毒", "17");
		dataset.addValue(0, "病毒", "18");
		dataset.addValue(0, "病毒", "19");
		dataset.addValue(0, "病毒", "20");
		dataset.addValue(0, "病毒", "21");
		dataset.addValue(0, "病毒", "22");
		dataset.addValue(0, "病毒", "23");
		dataset.addValue(0, "病毒", "24");
		dataset.addValue(0, "病毒", "25");
		dataset.addValue(0, "病毒", "26");
		dataset.addValue(0, "病毒", "27");
		dataset.addValue(0, "病毒", "28");
		dataset.addValue(0, "病毒", "29");
		dataset.addValue(0, "病毒", "30");
		
        
        JFreeChart chart=ChartFactory.createBarChart3D("2011年7月病毒数量图",
				"日期","病毒数量",dataset,PlotOrientation.VERTICAL,
				true,true,false);
	    chart.getTitle().setFont(new Font("宋体",Font.BOLD,15));
		CategoryPlot plot = chart.getCategoryPlot(); 
		NumberAxis vn = (NumberAxis) plot.getRangeAxis(); 
		vn.setAutoRangeIncludesZero(true); 

		CategoryAxis domainAxis = plot.getDomainAxis(); 

		domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
		// Lable 
		Font labelFont = new Font("宋体", Font.BOLD, 12); 

		domainAxis.setLabelFont(labelFont);
		domainAxis.setTickLabelFont(labelFont);

		domainAxis.setMaximumCategoryLabelWidthRatio(1f);
		// domainAxis.setVerticalCategoryLabels(false); 
		plot.setDomainAxis(domainAxis); 

		ValueAxis rangeAxis = plot.getRangeAxis(); 
		rangeAxis.setLabelFont(labelFont);
		rangeAxis.setTickLabelFont(labelFont);
		rangeAxis.setUpperMargin(0.15); 
		rangeAxis.setLowerMargin(0.15); 
		plot.setRangeAxis(rangeAxis); 
		BarRenderer renderer = new BarRenderer(); 
		renderer.setMaximumBarWidth(0.7); 
		renderer.setMinimumBarLength(10); 

		renderer.setBaseOutlinePaint(Color.BLACK); 

		renderer.setSeriesPaint(0, Color.GREEN); 
		renderer.setSeriesPaint(1, new Color(0, 0, 255)); 
		renderer.setItemMargin(0.25); 
		renderer 
		.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); 
		renderer.setBaseItemLabelsVisible(true); 

		plot.setRenderer(renderer); 
		plot.setForegroundAlpha(0.6f); 
		plot.setBackgroundAlpha(0.7f);
		
		chart.getLegend().setItemFont(labelFont);
        
        String fileName=ServletUtilities.saveChartAsJPEG(chart,500,300,session);
        String url=request.getContextPath()+"/DisplayChart?filename="+fileName;

 %>
 <img src="<%=url%>" width="700" height="300">
  </body>
</html>
